package com.yb.xczx.cloud.passport.config;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;

/**
 * Copyright (C), 2022-2023, 姚兵
 * Author: 32210
 * Date: 2023/5/19 16:02
 * FileName: FeignConfig
 * Description:
 */

public class FeignOauth2AuthConfig {

    //拦截器，每次访问在header里添加token
    private final String AUTHORIZATION_HEADER = "Authorization";
    private final String BEARER_TOKEN_TYPE = "Bearer";
    //拦截器，每次访问在header里添加token
    @Bean
    RequestInterceptor bearerRequestInterceptor(){
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate requestTemplate) {
                    requestTemplate.header(AUTHORIZATION_HEADER,String.format(BEARER_TOKEN_TYPE,""));
                    requestTemplate.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE);
            }
        };
    }
}
